home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / CAGDCSRF.C < prev    next >
C/C++ Source or Header  |  1991-10-09  |  3KB  |  89 lines

  1. /******************************************************************************
  2. * CagdCSrf.c - Constructa surface using a set of curves.                      *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Sep. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #ifdef __MSDOS__
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <alloc.h>
  11. #endif /* __MSDOS__ */
  12.  
  13. #include "cagd_loc.h"
  14.  
  15. /******************************************************************************
  16. * Constructs a surface using a set of curves. Curves are made to be          *
  17. * compatible and then each is substituted in the resulting surface as a row.  *
  18. *   Other direction order is at most the compatible curves order. If order is *
  19. * less than number of curves a knot vector is formed uniformly (open end).    *
  20. ******************************************************************************/
  21. CagdSrfStruct *CagdSrfFromCrvs(CagdCrvStruct *CrvList)
  22. {
  23.     CagdBType IsNotRational;
  24.     int i, j, NumCrvs, UOrder, VOrder, MaxCoord, Length;
  25.     CagdRType **SrfPoints;
  26.     CagdCrvStruct *Crv, **CrvVec;
  27.     CagdSrfStruct *Srf;
  28.  
  29.     /* Find out how many curves we have and put them in a linear vector.     */
  30.     /* Note the vector have a COPY of the curves so we can modify them.      */
  31.     for (NumCrvs = 0, Crv = CrvList;
  32.      Crv != NULL;
  33.      NumCrvs++, Crv = Crv -> Pnext);
  34.     CrvVec = (CagdCrvStruct **) CagdMalloc(sizeof(CagdCrvStruct *) * NumCrvs);
  35.     for (i = 0, Crv = CrvList;
  36.      i < NumCrvs;
  37.      i++, Crv = Crv -> Pnext)
  38.     CrvVec[i] = CagdCrvCopy(Crv);
  39.  
  40.     /* Traverse vector in a O(n^2) fashion and make all curves compatible.   */
  41.     for (i = 0; i < NumCrvs - 1; i++)
  42.     for (j = i + 1; j < NumCrvs; j++)
  43.         CagdMakeCrvsCompatible(&CrvVec[i], &CrvVec[j], TRUE, TRUE);
  44.  
  45.     /* Construct the surface. All required information is now available.     */
  46.     UOrder = CrvVec[0] -> Order;
  47.     VOrder = MIN(NumCrvs, UOrder);
  48.     if (NumCrvs == VOrder && CrvVec[0] -> GType == CAGD_CBEZIER_TYPE) {
  49.         /* Allocate a bezier surface. */
  50.     Srf = BzrSrfNew(CrvVec[0] -> Length, NumCrvs, CrvVec[0] -> PType);
  51.     }
  52.     else {
  53.     /* Allocate a bspline surface. */
  54.     Srf = BspSrfNew(CrvVec[0] -> Length, NumCrvs, UOrder, VOrder,
  55.             CrvVec[0] -> PType);
  56.     CagdFree((VoidPtr) Srf -> UKnotVector);
  57.     Srf -> UKnotVector = BspKnotCopy(CrvVec[0] -> KnotVector,
  58.                      CrvVec[0] -> Length + CrvVec[0] -> Order);
  59.     BspKnotUniformOpen(NumCrvs, VOrder, Srf -> VKnotVector);
  60.     }
  61.  
  62.     /* Substitute each curve as a row into the surface mesh and delete it. */
  63.     SrfPoints = Srf -> Points;
  64.     i = 0;
  65.     MaxCoord = CAGD_NUM_OF_PT_COORD(CrvVec[0] -> PType),
  66.     IsNotRational = !CAGD_IS_RATIONAL_CRV(CrvVec[0]);
  67.     Length = CrvVec[0] -> Length;
  68.  
  69.     for (j = 0; j < NumCrvs; j++) {
  70.     int k;
  71.     CagdRType **CrvPoints = CrvVec[j] -> Points;
  72.  
  73.         for (k = IsNotRational; k <= MaxCoord; k++)
  74.         GEN_COPY(&SrfPoints[k][i], CrvPoints[k], sizeof(CagdRType) * Length);
  75.  
  76.     CagdCrvFree(CrvVec[j]);
  77.     i += Length;
  78.     }
  79.  
  80.     CagdFree((VoidPtr) CrvVec);
  81.  
  82.     return Srf;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.